<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<link rel="stylesheet"
			href="/resources/plugins/datatables/dataTables.bootstrap.css" />
		<style>
#accountInfo .box-header {
	padding: 19px;
}

#statistics .box-title {
	font-size: 16px;
}

#vol p:nth-child(2) {
	font-size: 15px;
}

select {
	color: black;
}

.ui-autocomplete-input {
	width: 100%;
}
</style>
	</ui:define>
	<ui:define name="status">
		<!-- 长进度条 -->
		<p:ajaxStatus onstart="PF('statusDialog').show()"
			onsuccess="PF('statusDialog').hide()" />
		<p:dialog widgetVar="statusDialog" modal="true" draggable="false"
			closable="false" resizable="false" showHeader="false">
			<img src="#{request.contextPath}/resources/img/ajaxloadingbar.gif" />
		</p:dialog>
	</ui:define>
	<ui:define name="content">
		<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
			<p:commandButton value="是" type="button"
				styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
			<p:commandButton value="否" type="button"
				styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
		</p:confirmDialog>
		<div class='full-center-content-scroll-noheader'>
			<div class="nav-tabs-custom">
				<ul class="nav nav-tabs pull-left ">
					<li class="active"><a href="#modelForcecast" data-toggle="tab">模型预测</a></li>
					<li><a href="#modelTraining" id="deviceRelateTab"
						data-toggle="tab">模型训练</a></li>
				</ul>
				<div class="tab-content no-padding">
					<!-- 模型预测 -->
					<div class="chart tab-pane active" id="modelForcecast"
						style="position: relative">
						<!-- 隐藏字段，用来控制原因预测时的dialog -->
						<h:inputHidden id="resultFlag"
							value="#{faultReasonIdentifyController.resultFlag}" />
						<h:form id="form">
							<p:toolbar id="searchToobar">
								<f:facet name="left">
									<p:growl id="msgs" showDetail="true" />
									<h:outputText value="设备名称：" />
									<p:inputText
										value="#{faultReasonIdentifyController.faultEquipment}" />
									<p:outputLabel value="故障时间： " style="margin-left:5px" />
									<p:calendar pattern="yyyy-MM-dd" navigator="true"
										maxdate="Date()"
										value="#{faultReasonIdentifyController.startTime}"
										style="wigth:14px">
									</p:calendar>
									<p:outputLabel value="至 "
										style="margin-left:5px;margin-right:5px" />
									<p:calendar pattern="yyyy-MM-dd" navigator="true"
										maxdate="Date()"
										value="#{faultReasonIdentifyController.endTime}"
										style="wigth:14px">
									</p:calendar>
									<p:commandButton value="搜索"
										actionListener="#{faultReasonIdentifyController.search}"
										update="faultsTbs searchToobar msgs" icon="ui-icon-search"
										style="margin-left:5px" />
									<p:commandButton value="刷新"
										actionListener="#{faultReasonIdentifyController.refresh}"
										update="faultsTbs searchToobar" icon="ui-icon-refresh" />
									<p:commandButton value="原因预测"
										actionListener="#{faultReasonIdentifyController.multipleModelPredict}"
										update="faultsTbs searchToobar msgs messList resultFlag"
										oncomplete="showMessDialog()" icon="fa fa-lightbulb-o"
										rendered="#{s:hasPermission(session,'bhyx_sdyybs_yyyc')}" />
								</f:facet>
							</p:toolbar>
							<p:dialog widgetVar="receiveMessDialog" modal="true"
								closable="true" draggable="true" width="600" height="300">
								<p:dataList id="messList"
									value="#{faultReasonIdentifyController.resultMessList}"
									var="message" type="definition">
									#{message}
								</p:dataList>
							</p:dialog>
							<p:dataTable id="faultsTbs" var="anal" rowKey="#{anal.id}"
								rowIndexVar="ite"
								value="#{faultReasonIdentifyController.analLinefaultEtl}"
								emptyMessage="没有记录" lazy="true"
								selection="#{faultReasonIdentifyController.selectAnals}"
								style="margin-bottom:20px" rows="20" paginator="true"
								paginatorPosition="bottom"
								paginatorTemplate="{Customization} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
								rowsPerPageTemplate="20,50,100">
								<!-- <p:ajax event="rowSelect"></p:ajax>
								<p:ajax event="rowUnselect"></p:ajax> -->
								<f:facet name="{Customization}">
									<p:outputLabel
										value="总计：#{faultReasonIdentifyController.rowCount} 条记录"
										style="margin-right:20px;"></p:outputLabel>
								</f:facet>
								<p:column selectionMode="multiple"
									style="width:3%;text-align:center" />
								<p:column width="5%" headerText="序号 ">
									<h:outputText value="#{ite+1}" />
								</p:column>
								<p:column headerText="故障设备">
									<h:outputText value="#{anal.equipment}" />
								</p:column>
								<p:column headerText="故障时间">
									<h:outputText value="#{anal.time}">
										<f:convertDateTime pattern="yyyy-MM-dd HH:mm:ss"
											timeZone="GMT+8" />
									</h:outputText>
								</p:column>
								<p:column headerText="故障原因">
									<h:outputText value="#{anal.reason}" />
								</p:column>
								<p:column headerText="经度">
									<h:outputText value="#{anal.longitude}" />
								</p:column>
								<p:column headerText="纬度">
									<h:outputText value="#{anal.latitude}" />
								</p:column>
							</p:dataTable>
							<p:dialog widgetVar="showLog" header="日志" modal="true"
								id="showLog" width="900" height="600">
							</p:dialog>
						</h:form>
					</div>
					<!-- 模型训练 -->
					<div class="chart tab-pane" id="modelTraining"
						style="position: relative">
						<!-- 隐藏字段，用来控制模型训练时的dialog -->
						<h:inputHidden id="trainResFlag"
							value="#{faultReasonIdentifyController.trainResFlag}" />
						<h:form id="tranningForm">
							<div class='col-sm-12' style="font-size:">
								<div class='info-box' style='border: 1px solid #00c0ef;'>
									<span class='info-box-icon bg-aqua' style='font-size: 30px'>
										<i id='date'> 统计</i>
									</span>
									<div class='info-box-content' id='info' style='font-size: 20px'>
										<div class='col-sm-2 border-right'>
											<div class='description-block'>
												<p>模型数据总条数</p>
												<p class='text-blue'>#{faultReasonIdentifyController.dataMaxNum}</p>
											</div>
										</div>
										<div class='col-sm-2 border-right'>
											<div class='description-block'>
												<p>本次训练条数</p>
												<p class='text-green'>#{faultReasonIdentifyController.dataNum}</p>
											</div>
										</div>
										<div class='col-sm-2 border-right'>
											<div class='description-block'>
												<p>训练正确率</p>
												<p class='text-red'>#{faultReasonIdentifyController.correctnessRate}</p>
											</div>
										</div>
										<div class='col-sm-2  border-right' id='stationChart'
											style='height: 85px; margin: 0; padding: 10px;'></div>
									</div>
								</div>
							</div>
							<p:dialog widgetVar="trainingMessDialog" modal="true"
								closable="true" width="600" height="300">
								<p:outputLabel id="trainingResult"
									value="#{faultReasonIdentifyController.resultMess}" />
							</p:dialog>
						</h:form>
						<div class="col-sm-12" style="margin-top: 10px;">
							<div class="col-sm-2">
								<h3 class="box-title">模型管理：</h3>
								<p:commandButton value="新增模型" icon="ui-icon-document"
									actionListener="#{faultReasonIdentifyController.createModel}"
									oncomplete="PF('createDlg').show()"
									update="modelDataList createForm:createDetail"
									style="margin-left:10px;" />
								<h3 class="box-title">现有模型：</h3>
								<p:dataList id="modelDataList"
									value="#{faultReasonIdentifyController.modelTypeList}"
									var="modelType" type="none">
									<h:form id="modelForm">
										<p:toolbar id="existingToobar">
											<f:facet name="left">
												<p:growl id="existing" showDetail="true" />
												<p:commandButton value="#{modelType}模型"
													actionListener="#{faultReasonIdentifyController.getInputVectorByModelType(modelType)}"
													update="fileForm:fileTable tranningForm"
													icon="fa fa-hand-o-right" />
												<p:commandButton title="训练"
													update="tranningForm:trainingResult form:msgs trainResFlag tranningForm"
													actionListener="#{faultReasonIdentifyController.modelTrainingBP(modelType)}"
													oncomplete="showTrainMessDialog()" icon="ui-icon-bolt"
													rendered="#{s:hasPermission(session,'bhyx_sdyybs_xllj')}">
													<p:confirm header="提示" message="本次模型训练将会覆盖上次训练数据，确定开始训练吗？"
														icon="ui-icon-alert" />
												</p:commandButton>
												<p:commandButton title="删除模型"
													update="modelDataList existingToobar form:msgs"
													actionListener="#{faultReasonIdentifyController.deleteModel(modelType)}"
													icon="ui-icon-trash"
													rendered="#{s:hasPermission(session,'bhyx_sdyybs_xllj')}">
													<p:confirm header="提示" message="确定删除该记录吗?"
														icon="ui-icon-alert" />
												</p:commandButton>
												<p:commandButton title="编辑模型" icon="ui-icon-pencil"
													actionListener="#{faultReasonIdentifyController.editModel(modelType)}"
													oncomplete="PF('createDlg').show()"
													update="createForm:createDetail" />
											</f:facet>
										</p:toolbar>
									</h:form>
								</p:dataList>
							</div>
							<div class="col-sm-10">
								<h3 class="box-title">模型文件：</h3>
								<h:form id="fileForm">
									<p:dataTable id="fileTable" var="vector" rowKey="#{vector.id}"
										value="#{faultReasonIdentifyController.vecList}"
										emptyMessage="没有记录" scrollable="true" scrollHeight="550"
										style="margin-bottom:20px">
										<p:column headerText="春" width="3">
											<h:outputText value="#{vector.spring}" />
										</p:column>
										<p:column headerText="夏" width="3">
											<h:outputText value="#{vector.summer}" />
										</p:column>
										<p:column headerText="秋" width="3">
											<h:outputText value="#{vector.autumn}" />
										</p:column>
										<p:column headerText="冬" width="3">
											<h:outputText value="#{vector.winter}" />
										</p:column>
										<p:column headerText="清晨" width="3">
											<h:outputText value="#{vector.morning}" />
										</p:column>
										<p:column headerText="白天" width="3">
											<h:outputText value="#{vector.day}" />
										</p:column>
										<p:column headerText="傍晚" width="3">
											<h:outputText value="#{vector.evening}" />
										</p:column>
										<p:column headerText="午夜" width="3">
											<h:outputText value="#{vector.midnight}" />
										</p:column>
										<p:column headerText="重合闸" width="10">
											<h:outputText value="#{vector.reclosing}" />
										</p:column>
										<p:column headerText="雷电流幅值" width="3"
											rendered="#{faultReasonIdentifyController.lightingFlag}">
											<h:outputText value="#{vector.lighting}" />
										</p:column>
										<p:column headerText="覆冰厚度"
											rendered="#{faultReasonIdentifyController.iceFlag}" width="3">
											<h:outputText value="#{vector.iceHeight}" />
										</p:column>
										<p:column headerText="温度" width="3"
											rendered="#{faultReasonIdentifyController.tempFlag}">
											<h:outputText value="#{vector.temp}" />
										</p:column>
										<p:column headerText="湿度" width="3"
											rendered="#{faultReasonIdentifyController.rhumdFlag}">
											<h:outputText value="#{vector.rhumd}" />
										</p:column>
										<p:column headerText="风速" width="3"
											rendered="#{faultReasonIdentifyController.windFlag}">
											<h:outputText value="#{vector.wind}" />
										</p:column>
										<p:column headerText="风向" width="3"
											rendered="#{faultReasonIdentifyController.windDirFlag}">
											<h:outputText value="#{vector.windDir}" />
										</p:column>
										<p:column headerText="故障相直流分量" width="10">
											<h:outputText value="#{vector.electricityDir}" />
										</p:column>
										<p:column headerText="故障相三次谐波含量" width="10">
											<h:outputText value="#{vector.electricityHar}" />
										</p:column>
										<p:column headerText="本模型数据" width="5">
											<h:outputText value="#{vector.flag==1?'√':'×'}" />
										</p:column>
									</p:dataTable>
								</h:form>
								<h:form id="createForm">
									<p:dialog widgetVar="createDlg"
										header="#{faultReasonIdentifyController.createdModel.id == null?'新建':'编辑'}"
										modal="true" id="createDlg" width="600">
										<p:toolbar>
											<f:facet name="left">
												<p:commandButton value="保存" update="modelDataList"
													icon="ui-icon-disk" oncomplete="PF('createDlg').hide()"
													actionListener="#{faultReasonIdentifyController.saveModel}" />
											</f:facet>
										</p:toolbar>
										<p:outputPanel id="createDetail"
											style="text-align:center;width:100%;">
											<p:panelGrid
												rendered="#{not empty faultReasonIdentifyController.createdModel}"
												style="width:100%;">
												<p:row>
													<p:column>
														<h:outputText value="名称：" />
													</p:column>
													<p:column>
														<p:inputText required="true" requiredMessage="名称为必填项！"
															style="width:80%; margin-right:5px;"
															value="#{faultReasonIdentifyController.createdModel.name}" />模型
											</p:column>
												</p:row>
												<p:row>
													<p:column>
														<h:outputText value="描述：" />
													</p:column>
													<p:column>
														<p:inputText style="width:100%;"
															value="#{faultReasonIdentifyController.createdModel.description}" />
													</p:column>
												</p:row>

												<p:row>
													<p:column>
														<h:outputText value="文件路径：" />
													</p:column>
													<p:column>
														<p:inputText style="width:100%;"
															value="#{faultReasonIdentifyController.createdModel.filePath}" />
													</p:column>
												</p:row>
											</p:panelGrid>
										</p:outputPanel>
									</p:dialog>
								</h:form>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</ui:define>
	<ui:define name="contentend">
		<script src="/resources/plugins/datatables/jquery.dataTables.js"></script>
		<script
			src="/resources/plugins/datatables/dataTables.bootstrap.min.js"></script>
		<script src="/resources/js/tables/mytable.js"></script>
		<script src="/resources/js/mymodal.js"></script>
		<script>
			function showTrainMessDialog() {//训练成功时显示dialog
				var trainResFlag = $('#trainResFlag').val();
				if (trainResFlag == 'true') {
					PF('trainingMessDialog').show();
				}
			}
			function showMessDialog() {//原因预测时显示dialog
				var resultFlag = $('#resultFlag').val();
				if (resultFlag == "true") {
					PF('receiveMessDialog').show();
				}
			}

			function showDataTab() {
				$('#fileContentTabs li').each(function() {
					if ($(this).hasClass('active')) {
						$(this).removeClass('active');
					}
				});
				$('#dataFileLi').addClass('active');
				$('#contentDivs div').each(function() {
					if ($(this).hasClass('active')) {
						$(this).removeClass('active');
					}
				});
				$('#dataFile').addClass('active');
			}
		</script>
	</ui:define>
</ui:composition>
